<style>
	
</style>
<template>
<div>
    <Card :bordered="false" dis-hover>
        <p slot="title">用户及组织机构管理</p>
        <Row :gutter="20">
			<Col span="7">
				<p class="p_1">组织机构：</p>
				<Tree :data="data2" ref="tree" @on-select-change="change"></Tree>
				<!-- <Button type="primary" @click="addtype">添加</Button> -->
				<Button type="warning" @click="updatetype" >修改</Button>
				<!-- <Button type="error" @click="deletetype">删除</Button> -->
				
			</Col>
			<Col span="17">
				<p class="p_1">人员列表:
					
				</p>
				<div style="font-size:12px;" v-if="rightobj.title">
					<Row>
						<Col span="12">组织机构名称 ：{{rightobj.title}}</Col>
						<Col span="12">地 址、电 话 ：{{rightobj.addressPhone}}</Col>
					</Row>
					<Row>
						<Col span="12">开户行及帐号 ：{{rightobj.bankAccount}}</Col>
						<Col span="12">单张开票金额 (元)：{{rightobj.invoiceMaxAmount}}</Col>
					</Row>
				</div>
				
				<div style="margin-top:10px;">

					

					<div class="ivu-table-wrapper" >
			            <div class="ivu-table ivu-table-with-fixed-top ">
			                <div class="ivu-table-body" >
								
			                    <table  class="table_border _table"   cellspacing="0" cellpadding="0" border="0" style="width: 100%;">
				                   
				                    <thead>
					                    <tr>
					                        <th class="" style="width:50px;">
					                            <div class="ivu-table-cell">
					                                <span>	序号</span>
					                            </div>
					                        </th>
					                        <th class="">
					                            <div class="ivu-table-cell">
					                                <span>用户名</span>
					                            </div>
					                        </th>
					                        <th class="">
					                            <div class="ivu-table-cell">
					                                <span>所属集团</span>
					                            </div>
					                        </th>
					                        <th class="" style="width:100px;">
					                            <div class="ivu-table-cell">
					                                <span>用户类型</span>
					                            </div>
					                        </th>
					                        <th class="" style="width:100px;">
					                            <div class="ivu-table-cell">
					                                <span>注册时间</span>
					                            </div>
					                        </th>
					                        <th class="" style="width:110px;">
					                            <div class="ivu-table-cell">
					                                <span>	操作</span>
					                            </div>
					                        </th>
					                    </tr>
				                    </thead>
				                    <tbody class="ivu-table-tbody">
					                    <tr class="ivu-table-row" v-for="(item,index) in data">
					                        <td class="">
					                            <div class="ivu-table-cell">
					                                <span>{{index+1}}</span>
					                            </div>
					                        </td>
					                        <td class="">
					                            <div class="ivu-table-cell">
					                                <span>{{item.userName}}</span>
					                            </div>
					                        </td>
					                        <td class="">
					                            <div class="ivu-table-cell">
					                                <span>	{{item.orgName}}</span>
					                            </div>
					                        </td>
					                        <td class="">
					                            <div class="ivu-table-cell">
					                                <span>	{{item.userType | decode('usertype')}}</span>
					                            </div>
					                        </td>
					                        <td class="">
					                            <div class="ivu-table-cell">
					                               {{item.createDate | formatDate('yyyy-MM-dd')}}
					                            </div>
					                        </td>
					                        <td class="">
					                            <div class="ivu-table-cell">
					                                <Button  size="small" type="error" 
					                                @click="deleteuser(item)">删除</Button>
					                                <Button  size="small" type="warning" 
					                                @click="updateuser(item)">修改</Button>
					                            </div>
					                        </td>
					                    </tr>
				                    </tbody>
			                    </table>
			                    <div class="body_empty" v-if="data.length==0 ">
			                    	暂无数据
			                    </div>
			                </div>
			            </div>
			            
			        </div>
		       	</div>
		       	<p style="margin-top:20px;">
					<Button type="primary" @click="adduser">添加</Button>
					<Page :total="page.total" :current="page.currentPage" placement="top" :page-size="page.pageSize"   @on-change="changePage" show-total style="float: right;"></Page>
				</p>
			</Col>
        </Row>
    </Card>
    <Modal
        :title="title"
        v-model="modal">
        
		<Row>
			<Col span="6">组织机构名称 ：</Col>
			<Col span="18"><Input v-model="value" placeholder="请输入" style="width: 300px" 
			disabled></Input></Col>
		</Row> <br>
		<Row>
			<Col span="6">地 址、电 话 ：</Col>
			<Col span="18"><Input v-model="addressPhone" placeholder="请输入" style="width: 300px"></Input></Col>
		</Row> <br>
		<Row>
			<Col span="6">开户行及帐号 ：</Col>
			<Col span="18"><Input v-model="bankAccount" placeholder="请输入" style="width: 300px"></Input></Col>
		</Row> <br>
		<Row>
			<Col span="6">单张开票金额(元)：</Col>
			<Col span="18"><Input v-model="invoiceMaxAmount" placeholder="请输入" style="width: 300px"></Input></Col>
		</Row>
        
         
		 
		 <div slot="footer">
            <Button @click="cancel()">关闭</Button>
			<Button @click="add()" v-show="title=='添加'">添加</Button>
			<Button @click="update()" v-show="title=='修改'">修改</Button>
        </div>
    </Modal>
	<user-edit @refresh="getuser"></user-edit>
</div>	
</template>
<script>
import UserEdit from "../Module/useredit.vue";
export default {
	components:{UserEdit},
	data (){
		return {
			modal:false,value:'',title:'添加',addressPhone:'',
			rightobj:{},
			bankAccount:'',invoiceMaxAmount:'',
			colors:['yellow','blue'],texts:['正常','禁用'],
			data2:[],
			page:{total:0,currentPage:1,pageSize:10},
			data:[
				
			]
		}
	},mounted(){
		$('._table').resizableColumns({});
	},methods:{
		changePage (pageNum){
			this.page.currentPage = pageNum;
     		this.getuser();
		},
		addtype(){
			var d=this.$refs.tree.getSelectedNodes();
			if(d.length>0){
				this.id=d[0].id;
			}else{
				this.$Message.error('请选择要添加的节点!');
				return ;
			}

			this.modal=true;
			this.title='添加'
			this.value='';
		},updatetype(){
			var d=this.$refs.tree.getSelectedNodes();
			
			if(d.length>0){
				this.id=d[0].guid;
				this.value=d[0].title;
				this.addressPhone=d[0].addressPhone;
				this.bankAccount=d[0].bankAccount;
				this.invoiceMaxAmount=d[0].invoiceMaxAmount;
			}else{
				this.$Message.error('请选择要修改的节点!');
				return ;
			}
			this.modal=true;
			this.title='修改'
			
		},deletetype(){
			var d=this.$refs.tree.getSelectedNodes();
			if(d.length>0){
				this.id=d[0].id;
				this.value=d[0].title
			}else{
				this.$Message.error('请选择要删除的节点!');
				return ;
			}
			this.$Modal.confirm({
                 title:'删除提示',
                 content: '<p>确定删除？</p>',
                 onOk:()=>{
                     this.axios.post('/',{id:this.id}).then((res)=>{
                        this.$Message.info(res.message);
                        this.getdata();
                    })
                }
            })
		},cancel(){
			this.modal=false;
		},add(){
			this.axios.post('/',{
				id:this.id,title:this.value,invoiceMaxAmount:this.invoiceMaxAmount,
				addressPhone:this.addressPhone,bankAccount:this.bankAccount
				}).then((res)=>{

			})
			this.modal=false;
			this.title='';
			this.$Message.success('添加成功!');
			this.getdata();
		},update(){
			this.axios.post('/company/update',
				{
					guid:this.id,name:this.value,
					bankAccount:this.bankAccount,addressPhone:this.addressPhone,
					invoiceMaxAmount:this.invoiceMaxAmount
				}).then((res)=>{
					//console.log(res);
					if(res.errorCode==0){
						this.modal=false;
						this.title='';
						this.$Message.success('修改成功!');
						this.getdata();
					}else{
						this.$Message.error(res.message);
					}
					
			})
			
		},getdata(){
			var id=this.$store.getters.getUserinfo.sysComGuid;
			//id=1;
			this.axios.post('/company/tree/'+id,{}).then((res)=>{
				console.log(res);
				var u=JSON.stringify(res);
				u=u.replace(/comName/g,'title');
				u=JSON.parse(u);
				var d=[{}];
				d[0].title=u.data.title;
				d[0].createDate=u.data.createDate;
				d[0].guid=u.data.guid;
				d[0].memo=u.data.memo;
				d[0].orgCode=u.data.orgCode;
				d[0].parentGuid=u.data.parentGuid;
				d[0].taxNo=u.data.taxNo;
				d[0].children=u.data.children;
				d[0].addressPhone=u.data.addressPhone;
				d[0].bankAccount=u.data.bankAccount;
				d[0].invoiceMaxAmount=u.data.invoiceMaxAmount;
				this.data2=d;
			})
		},deleteuser(item){
			this.$Modal.confirm({
                 title:'删除提示',
                 content: '<p>确定删除？</p>',
                 onOk:()=>{
                     this.axios.post('/user/delete/'+item.guid,{}).then((res)=>{
                     	if(res.errorCode==0){
                     		this.$Message.info(res.message);
                     		this.page.currentPage=1;
                        	this.getuser();
                     	}
                        
                    })
                }
            })
		},updateuser(item){
			//this.$bus.emit('bus_useredit',{
			// 	id:1,username:'cc',password:'111',realname:'a',state:1
			// })
			this.$bus.emit('bus_useredit',item);
		},adduser(){
			var d=this.$refs.tree.getSelectedNodes();
			
			if(d.length>0){
				this.id=d[0].guid;
				this.value=d[0].title
			}else{
				this.$Message.error('请选择要添加的节点!');
				return ;
			}
			this.$bus.emit('bus_useredit',{
				userName:'',userPwd:'',orgGuid:this.page.orgGuid,userType:null
			})
		},getuser(){
			this.axios.post('/user/findbypage',this.page).then((res)=>{
				console.log(res);
				if(res.errorCode==0){
					this.data=res.data.list;
					this.page.total=res.data.total;
					this.page.currentPage=res.data.pageNo  || 1;
				}
			})
		},change(){
			var d=this.$refs.tree.getSelectedNodes();
			this.page.orgGuid=d[0].guid;
			this.rightobj.title=d[0].title;
			this.rightobj.addressPhone=d[0].addressPhone;
			this.rightobj.bankAccount=d[0].bankAccount
			this.rightobj.invoiceMaxAmount=d[0].invoiceMaxAmount;
			this.getuser();
		}
	},created(){
		this.getdata();
	},activated(){
		this.getdata();
	}
}
</script>